package com.hiwetop.cp;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.druid.DruidPlugin;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by linyu on 2016/12/26.
 */
public class DbUtil {
    static {
        DruidPlugin dp = new DruidPlugin("jdbc:mysql://192.168.0.114:3306/proxy?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull", "root", "login");
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
// 与web环境唯一的不同是要手动调用一次相关插件的start()方法
        try {
            dp.getDataSource().setLogWriter(new PrintWriter(new OutputStreamWriter(System.out, "utf-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }
        dp.start();
        arp.start();
    }

    public static void insertDb(String tableName, List list,int max){
        Db.batchSave(tableName,list,max);
    }
}
